package com.example.mpandroidchart1107;

import androidx.appcompat.app.AppCompatActivity;

import android.graphics.Color;
import android.os.Bundle;

import com.github.mikephil.charting.charts.LineChart;
import com.github.mikephil.charting.data.Entry;
import com.github.mikephil.charting.data.LineData;
import com.github.mikephil.charting.data.LineDataSet;
import com.github.mikephil.charting.interfaces.datasets.ILineDataSet;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        LineChart linechart = findViewById(R.id.linechart);
        float[] f1 = {9.0f, 6.0f, 9.0f, 9.0f, 6.0f, 9.0f, 9.0f, 6.0f, 9.0f};
        float[] f2 = {2.0f, 5.0f, 2.0f, 2.0f,5.0f, 2.0f, 2.0f, 5.0f, 2.0f};
        List<ILineDataSet>s= new ArrayList<>();
      LineDataSet demo1 = getDataSet(f1,"demo1");
      demo1.setColor(Color.parseColor("#ff0000"));
      demo1.setLineWidth(1.6f);
      demo1.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
      s.add(demo1);

      LineDataSet demo2 = getDataSet(f2,"demo2");
        demo2.setColor(Color.parseColor("#00ff00"));
        demo2.setLineWidth(3.2f);
        demo2.setMode(LineDataSet.Mode.HORIZONTAL_BEZIER);
        s.add(demo2);

        linechart.getLineData();
        linechart.setData(new LineData(s));
        linechart.invalidate();
        }
        private LineDataSet getDataSet(float[] f ,String title){
        List<Entry>data = new ArrayList<>();
        for (int x = 0;x< f .length;x++){
            Entry entry = new Entry(x,f[x]);
            data.add(entry);
            }
        return  new LineDataSet(data,title);
        }

    }


